//
//  CZHomeViewController.m
//  12期微博
//
//  Created by apple on 15-1-29.
//  Copyright (c) 2015年 itcast. All rights reserved.
//

#import "CZHomeViewController.h"
#import "CZTool.h"

@interface CZHomeViewController ()

@end

@implementation CZHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    

    // 1.初始化导航条
    // 创建左边和右边按钮
    /*
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"navigationbar_friendsearch"] style:UIBarButtonItemStylePlain target:nil action:nil];
    item.tintColor = [UIColor redColor];
     */
    /*
    // 创建按钮
    UIButton *leftBtn = [[UIButton alloc] init];
    // 设置对应状态图片
    [leftBtn setImage:[UIImage imageNamed:@"navigationbar_friendsearch"] forState:UIControlStateNormal];
    [leftBtn setImage:[UIImage imageNamed:@"navigationbar_friendsearch_highlighted"] forState:UIControlStateHighlighted];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    // 设置frame
    leftBtn.size = leftBtn.currentImage.size;
    self.navigationItem.leftBarButtonItem = leftItem;
    
    
    // 创建按钮
    UIButton *rightBtn = [[UIButton alloc] init];
    // 设置对应状态图片
    [rightBtn setImage:[UIImage imageNamed:@"navigationbar_pop"] forState:UIControlStateNormal];
    [rightBtn setImage:[UIImage imageNamed:@"navigationbar_pop_highlighted"] forState:UIControlStateHighlighted];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    // 设置frame
    rightBtn.size = rightBtn.currentImage.size;
    self.navigationItem.rightBarButtonItem = rightItem;
    */
    
    /*
    self.navigationItem.leftBarButtonItem = [self itemWithImage:@"navigationbar_friendsearch" higImage:@"navigationbar_friendsearch_highlighted" action:@selector(friendsearch)];
    self.navigationItem.rightBarButtonItem = [self itemWithImage:@"navigationbar_pop" higImage:@"navigationbar_pop_highlighted" action:@selector(scan)];
     */
    
    /*
    self.navigationItem.leftBarButtonItem = [CZTool itemWithImage:@"navigationbar_friendsearch" higImage:@"navigationbar_friendsearch_highlighted" target:self  action:@selector(friendsearch)];
    self.navigationItem.rightBarButtonItem = [CZTool itemWithImage:@"navigationbar_pop" higImage:@"navigationbar_pop_highlighted" target:self action:@selector(scan)];
     */
    /*
     思想;
     1.先分析如何实现
     2.重复代码过多-->抽取
     3.复用性太差 -->再次抽取(工具类)
     4.编码风格不符 -->再次抽取(分类)
     */
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithImage:@"navigationbar_friendsearch" higImage:@"navigationbar_friendsearch_highlighted" target:self  action:@selector(friendsearch)];
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithImage:@"navigationbar_pop" higImage:@"navigationbar_pop_highlighted" target:self action:@selector(scan)];
}

/**
 *  创建UIBarButtonItem
 *
 *  @param image    默认状态图片
 *  @param higImage 高亮状态图片
 *
 *  @return item
 */
- (UIBarButtonItem *)itemWithImage:(NSString *)image higImage:(NSString *)higImage action:(SEL)action;
{
    UIButton *btn = [[UIButton alloc] init];
    // 设置对应状态图片
    [btn setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:higImage] forState:UIControlStateHighlighted];
    // 设置frame
    btn.size = btn.currentImage.size;
    // 添加监听事件
    [btn addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
    
    return [[UIBarButtonItem alloc] initWithCustomView:btn];
}

#pragma mark - 内部控制方法
- (void)friendsearch
{
    DDActionLog;
}

- (void)scan
{
    DDActionLog;
}



@end
